//
//  YYYNavigationController.swift
//  Sina12
//
//  Created by yang on 2017/9/21.
//  Copyright © 2017年 成品家（北京）网络科技有限公司. All rights reserved.
//

import UIKit

class YYYNavigationController: UINavigationController
{
    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏导航条
        navigationBar.isHidden = true
        
    }
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {

        if childViewControllers.count > 0
        {
            //如果不是栈底控制器，隐藏底部分栏
            viewController.hidesBottomBarWhenPushed = true
            if let vc = viewController as? YYYBaseViewController
            {
                var backTitle = "返回"
                
                //如果是栈底控制器
                if childViewControllers.count == 1
                {
                    backTitle = childViewControllers[0].title ?? "返回"
                        //childViewControllers.first?.title ?? "返回"
                }
                vc.customNavigationItem.leftBarButtonItem = UIBarButtonItem(title: backTitle, target: self, action: #selector(popBack), isBack: true)
            }
        }
        super.pushViewController(viewController, animated: true)
    }
    
    @objc private func popBack()
    {
        popViewController(animated: true)
    }
}
